package com.zmzncs.lmtc.module.order.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zmzncs.lmtc.common.util.DateTimeUtil;
import com.zmzncs.lmtc.module.customer.dao.CarDao;
import com.zmzncs.lmtc.module.customer.dao.CardDao;
import com.zmzncs.lmtc.module.customer.pojo.car.CarDTO;
import com.zmzncs.lmtc.module.customer.pojo.card.CardDTO;
import com.zmzncs.lmtc.module.order.dao.OrderInfoDao;
import com.zmzncs.lmtc.module.order.dao.OrderTradeRecordDao;
import com.zmzncs.lmtc.module.order.pojo.order_Info.*;
import com.zmzncs.lmtc.module.order.pojo.order_trade_record.OrderTradeRecordDTO;
import com.zmzncs.lmtc.module.order.service.OrderInfoService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * <p>
 * 客户-信息 服务实现类
 * </p>
 *
 * @author 任建波
 * @since 2020-09-01
 */
@Slf4j
@Service
public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoDao, OrderInfo> implements OrderInfoService {

    @Autowired
    private OrderInfoDao orderInfoDao;
    @Autowired
    OrderTradeRecordDao orderTradeRecordDao;
    @Autowired
    CardDao cardDao;
    @Autowired
    CarDao carDao;

    @Override
    public IPage<OrderInfoDTO> getOrderByManage(OrderInfoManageForm form) {
        Page page = new Page<>(form.getCurrent(), form.getSize());

        IPage<OrderInfoDTO> infoDTOIPage = orderInfoDao.getOrderList(page, form);
        if (infoDTOIPage != null && infoDTOIPage.getRecords() != null && !infoDTOIPage.getRecords().isEmpty()){
            for (OrderInfoDTO record : infoDTOIPage.getRecords()) {

                if (record.getParkDuration() != null){
                    String hourByMinute = DateTimeUtil.toHourByMinute(record.getParkDuration());
                    record.setParkingTime(hourByMinute);
                }
            }
        }

        return infoDTOIPage;
    }

    /**
     * 大数据展示——获取入场记录
     * @return
     */
    public List<CarInModel> getCarInList(){
        List<CarInModel> list = orderInfoDao.getCarInList();
        if (list != null && !list.isEmpty()){
            for (CarInModel model : list) {
                String date = DateTimeUtil.convertYMD(new Date());
                model.setInTime(date);
            }
        }
        return list;
    }

}
